package comparisons

import "jvmgo/ch05/instructions/base"
import "jvmgo/ch05/rtda"

// if == 0
type IFEQ struct {
    base.BranchInstruction
}

func (self *IFEQ) Execute(frame *rtda.Frame) {
    val := frame.OperandStack().PopInt()
    if val == 0 {
        base.Branch(frame, self.Offset)
    }
}

//if != 0
type IFNE struct {
    base.BranchInstruction
}

func (self *IFNE) Execute(frame *rtda.Frame) {
    val := frame.OperandStack().PopInt()
    if val != 0 {
        base.Branch(frame, self.Offset)
    }
}

//if x < 0
type IFLT struct {
    base.BranchInstruction
}

func (self *IFLT) Execute(frame *rtda.Frame) {
    val := frame.OperandStack().PopInt()
    if val < 0 {
        base.Branch(frame, self.Offset)
    }
}

//if <= 0
type IFLE struct {
    base.BranchInstruction
}

func (self *IFLE) Execute(frame *rtda.Frame) {
    val := frame.OperandStack().PopInt()
    if val <= 0 {
        base.Branch(frame, self.Offset)
    }
}

//if > 0
type IFGT struct {
    base.BranchInstruction
}

func (self *IFGT) Execute(frame *rtda.Frame) {
    val := frame.OperandStack().PopInt()
    if val > 0 {
        base.Branch(frame, self.Offset)
    }
}

//if >= 0
type IFGE struct {
    base.BranchInstruction
}

func (self *IFGE) Execute(frame *rtda.Frame) {
    val := frame.OperandStack().PopInt()
    if val >= 0 {
        base.Branch(frame, self.Offset)
    }
}
